<?php

function DelComment($id)
{	
	$result = mysql_query("select * from blog_comment where comm_ID = $id limit 1") or die(mysql_error());
	$rs = mysql_fetch_object($result);
	$log_ID = $rs->comm_LogID;
	
	$sql = "delete from blog_comment where comm_ID= $id limit 1";
    mysql_query($sql) or die(mysql_error());
	
	UpdateComm($log_ID);
}

function DelArticle($id)
{
    $sql = "delete from blog_article where log_ID = $id limit 1";
	$ret = mysql_query($sql) or die (mysql_error());
	$sql = "select comm_ID from blog_comment where comm_LogID = $id";
	$result = mysql_query($sql) or die(mysql_error());
	while($rs=mysql_fetch_object($result))
	{
	     DelComment($rs->comm_ID);
	}
	return $ret;
}

function DelCategory($id)
{		
	$sql = "delete from blog_category where cate_ID= $id limit 1";
    mysql_query($sql) or die(mysql_error());
	$sql = "select log_ID from blog_article where log_CateID = $id";
	$result = mysql_query($sql) or die(mysql_error());
	while($rs=mysql_fetch_object($result))
	{
	     DelArticle($rs->log_ID);
	}
	return $ret;
}

function UpdateComm($logID)
{
    $sql = "SELECT count(*) from blog_comment where comm_LogID = $logID";
	$result = mysql_query($sql) or die(mysql_error());
	$rs = mysql_fetch_array($result);
	$commnums = empty($rs[0])?0:$rs[0];
	$sql = "UPDATE blog_article SET log_CommNums = $commnums WHERE log_ID = $logID";
	mysql_query($sql) or die(mysql_error());
}

function UpdateView($logID)
{
    $sql = "SELECT log_ViewNums from blog_article where log_ID = $LogID";
	$result = mysql_query($sql);
	$rs = mysql_fetch_array($result);
	$viewnums = empty($rs[0])?0:$rs[0];
	$viewnums ++;
	$sql = "UPDATE blog_article SET log_ViewNums = $viewnums WHERE log_ID = $logID";
	mysql_query($sql) or die(mysql_error());
}

function DelLink($id)
{		
	$sql = "delete from blog_link where link_ID= $id limit 1";
    mysql_query($sql) or die(mysql_error());
}

function ShowCategory($default_cateID)
{
    $sql = "select * from blog_category ";
	$result = mysql_query($sql) or die(mysql_error());
	echo "<select name='category' id='category'>\n";
	while($rs = mysql_fetch_object($result))
	{
	   if($rs->cate_ID == $default_cateID)
	   { echo "<option value='$rs->cate_ID' SELECTED>$rs->cate_Name</option>\n"; }
	   else{ echo "<option value='$rs->cate_ID'>$rs->cate_Name</option>\n"; }
	}
	echo "</select>\n";
}

?>